Skip to main content

Creating event bus adapters

Implementing your custom IEventBusAdapter

In order to create an adapter you need to implement the IEventBusAdapter contract.

Testing your custom IEventBusAdapter

We provide a complete test suite to verify your event bus adapter implementation. Simply use the eventBusAdapterTestSuite function:

  • Preconfigured Vitest test cases
  • Standardized event bus behavior validation
  • Common edge case coverage

Usage example:

// filename: MyEventBusAdapter.test.ts

import { describe, test, beforeEach, expect } from "vitest";
import { eventBusAdapterTestSuite } from "@daiso-tech/core/event-bus/test-utilities";
import { MyEventBusAdapter } from "./MyEventBusAdapter.js";

describe("class: MyEventBusAdapter", () => {
eventBusAdapterTestSuite({
createAdapter: () => new MyEventBusAdapter(),
test,
beforeEach,
expect,
describe,
});
});

Implementing your custom IEventBus class

In some cases, you may need to implement a custom EventBus class to optimize performance for your specific technology stack. You can then directly implement the IEventBus contract.

Testing your custom IEventBus class

We provide a complete test suite to verify your custom event bus class implementation. Simply use the eventBusTestSuite function:

  • Preconfigured Vitest test cases
  • Standardized event bus behavior validation
  • Common edge case coverage

Usage example:

// filename: MyEventBus.test.ts

import { describe, test, beforeEach, expect } from "vitest";
import { eventBusTestSuite } from "@daiso-tech/core/event-bus/test-utilities";
import { MyEventBus } from "./MyEventBus.js";

describe("class: EventBus", () => {
eventBusTestSuite({
test,
expect,
describe,
beforeEach,
createEventBus: () =>
new MyEventBus(),
});
});